﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using AnyGrid.Metadata;
using AnyGrid.Renderers;

namespace AnyGrid
{
    public class GridViewOptions
    {
        private IDictionary<string, ColumnOptionCollection> _columnOptions = new Dictionary<string, ColumnOptionCollection>();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification="Making this read-write enables use of initializers in views.")]
        public IDictionary<string, ColumnOptionCollection> ColumnOptions { get { return _columnOptions; } set { _columnOptions = value; } }

        /// <summary>
        /// Initial page. 1-based, like the grid. Default value is 1.
        /// </summary>
        [DefaultValue(1)]
        public int CurrentPage { get; set; }

        /// <summary>
        /// HTML id for table element. Required by jqGrid
        /// </summary>
        public string GridHtmlId { get; set; }

        /// <summary>
        /// If true, shows a checkbox at the left-hand side of each grid row.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multiselect", Justification="This is a jqGrid property name.")]
        public bool Multiselect { get; set; }

        /// <summary>
        /// True to include a pager control.
        /// </summary>
        public bool Pager { get; set; }

        private string _pagerHtmlId { get; set; }
        /// <summary>
        /// Html id for pager's div. Default value is the GridHtmlId + "Pager"
        /// </summary>
        public string PagerHtmlId
        {
            get
            {
                return _pagerHtmlId ?? this.GridHtmlId + "Pager";
            }
            set
            {
                _pagerHtmlId = value;
            }
        }

        private BaseGridRenderer _renderer;
        /// <summary>
        /// If set, specifies the grid to render. If null, GridRenderers.Current will be used.
        /// </summary>
        public BaseGridRenderer Renderer
        {
            get
            {
                return _renderer ?? GridRenderers.Current;
            }
            set
            {
                _renderer = value;
            }
        }

        /// <summary>
        /// True to include a separate search box above grid.
        /// </summary>
        public bool Search { get; set; }

        private string _searchHtmlId { get; set; }
        /// <summary>
        /// Html id for search box's div. Default value is the GridHtmlId + "Search"
        /// </summary>
        public string SearchHtmlId
        {
            get
            {
                return _searchHtmlId ?? this.GridHtmlId + "Search";
            }
            set
            {
                _searchHtmlId = value;
            }
        }

        public GridViewOptions()
        {
            this.CurrentPage = 1;
        }
    }
}
